<?php

include_once 'dbtable.php';

//lay danh sach post
function get_all_posts(pager $page,$url) {
    $sql = "select post.*,user.* from post,user where post.user_id = user.id and post.status = 1 order by post.id desc";
    return DbTable::Paging($page, $sql, $url,15);
}
//get post chi tiet
function get_post_chi_tiet($id) {
    $sql = "select post.*,user.* from post,user where post.user_id = user.id and post.status = 1 and post.id = '{$id}'";
    return DbTable::getData($sql);
}
//them moi post
function them_moi_post($array) {
    if (DbTable::insert("post", $array)) {
        return true;
    }
    return false;
}

//xoa post
function xoa_post($id) {
    
    if(mysql_query("delete from comment where post_id = '{$id}'")){
        if (DbTable::delete("post", $id)) {
            return true;
        }
    }
    return false;
}
//lay so nguoi comment
function get_count_comment($id) {
    $sql = "select * from comment where post_id='{$id}'";
    $countcomment = count(DbTable::getData($sql));
    return $countcomment;
}
//lay email de gui
function get_mailer() {
    $sql = "select email from user";
    return DbTable::getData($sql);
}

?>
